package cn.tedu.serviceBase.handler;

import cn.tedu.commonUtils.R;
import cn.tedu.serviceBase.exception.EducationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error().msg("服务器异常");
    }

    @ExceptionHandler(EducationException.class)
    @ResponseBody
    public R error(EducationException e){
        e.printStackTrace();
        return R.error().msg(e.getMsg()).state(e.getStatus());
    }
}
